#ifndef FILECLIENT_H
#define FILECLIENT_H

#include <QObject>
#include <QWebSocket>
#include <QFile>
#include <QTimer>
class FileClient : public QObject
{
    Q_OBJECT
public:
    explicit FileClient(QObject *parent = 0);
    ~FileClient();

    void setFilePos(qint64 pos);
    void setLength(qint64 length);
    void setFileName(const QString &fileName);
    void open(const QUrl &url);
    void setSize(qint64 size);
    void setMD5(const QString &md5);
    QString token() const;
signals:
    void closed();
    void progress(qint64 received, qint64 total);
public slots:
    void onConnected();
    void onBinaryMessageReceived(const QByteArray &message);
    void onTextMessageReceived(const QString &message);
    void processPong(quint64 elapsedTime, const QByteArray & payload);
    void processTimerPingPong();
    void error(QAbstractSocket::SocketError error);
private:
    QWebSocket m_webSocket;
    qint64 m_pos;
    qint64 m_length;
    qint64 m_size;
    QFile *m_file;
    QString m_token;
    QString m_md5;
    quint16 m_chksum;
    bool m_pong;
    QTimer m_timer;
};

#endif // FILECLIENT_H
